package com.example.demo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

//@Aspect
@Component
@Slf4j
public class TimeRecordAspect {

    //作用域,执行路径
//    @Around("execution(* com.example.demo.controller.*.*(..))")
    @Around("com.example.demo.aspect.AspectDemo.pt()")
    public Object timeRecord(ProceedingJoinPoint pjt){
        //1.记录开始时间
        //2.执行目标方法时间
        //3.记录结束时间
        //4.返回结果
        long start = System.currentTimeMillis();

        log.info("timeRecord.Around ⽅法开始执⾏");
        //执行目标方法
        Object o = null;
        try {
             o = pjt.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();


        log.info(pjt.getSignature() + "耗时: "+ (end - start)+ "ms");
        log.info("timeRecord.Around ⽅法结束执⾏");

        return o;
    }
}
